Source code for /engineering/webperf/master-v2[j1.2]/HTTPPush.javaOriginal file HTTPPush.java
   1 import java.io.*;
   2 import java.net.*;
   3 import java.util.*;
   4 
   5 public class HTTPPush extends Thread {
   6    
   7    MCommandQueue		myQueue;
   8    MCommand			currentCommand;
   9    MEvent			responseEvent;
  10    MEventQueue		eventQueue;
  11 
  12    SessionLog		myLog;	// for timing
  13    public 			boolean   idle  = true;
  14 
  15    URL			targetURL;
  16    String			targetURLText;
  17    int			myID;
  18 
  19    String[]			cmdNameTable = { "null", "new", "stop", "pause", "target",
  20 						     "getlog", "go", "ping" };
  21 
  22    private final static String	wordError = "!ERROR!";
  23    private final static String	wordSucc  = "SUCCESS";
  24    private final static String	noteFrame = "PRE>";
  25 
  26    // Use default constructor
  27 
  28    public void init(MCommandQueue yourQueue, SessionLog  yourLog,
  29 			  MEventQueue   myEventQueue, int      yourID) {
  30       setDaemon(true);
  31 	myQueue = yourQueue;
  32 	myLog   = yourLog;
  33 	eventQueue = myEventQueue;
  34 	myID 	  = yourID;
  35    }
  36 
  37    public void run() {
  38 
  39 	Hashtable	info, headers;
  40 	String	response;
  41 
  42 	int 		left, right;
  43 	
  44 	headers = new Hashtable();
  45 	headers.put("User-Agent", "JF Perf Tool Master");
  46 
  47 	// Loop until killed by the world
  48 	while(true) {
  49 		if (myQueue.has() == true)
  50 		{
  51 			idle   	   = false;
  52 			currentCommand = myQueue.get();
  53 
  54 			responseEvent =  new MEvent();
  55 			responseEvent.event = MEvent.eventSLAVE_RESPONSE;
  56 			responseEvent.index = currentCommand.command;
  57 			responseEvent.id    = myID;
  58 
  59 			switch(currentCommand.command) {
  60 			
  61 			   case MCommand.cmdNEW:
  62 			   case MCommand.cmdSTOP:
  63 			   case MCommand.cmdPAUSE:
  64 			   case MCommand.cmdTARGET:
  65 			   case MCommand.cmdGETLOG:
  66 			   case MCommand.cmdGO:
  67 			   case MCommand.cmdPING:
  68 // System.out.println("slave command : " + currentCommand.command + "\n");
  69 			       info = new Hashtable();
  70 				 info.put("command", cmdNameTable[currentCommand.command]);
  71 				 info.put("integer", Integer.toString(currentCommand.value));
  72 				 info.put("long",    Long.toString(currentCommand.lvalue));
  73 				 info.put("string",  currentCommand.item);
  74 	 
  75 				 try {
  76 				    targetURL = new URL(targetURLText);
  77 				    response = CGIpost.post(targetURL, headers, info);
  78 
  79 				    // See if it worked of didn't
  80 				    if (response.indexOf(wordError) == -1) {
  81 
  82 				       // kinda ass-backwards logic here.  *shrug*
  83 					 // this case means things are bad
  84 					 responseEvent.value = MEvent.rSUCCESS;
  85 
  86 				    } else {
  87 					 responseEvent.value = MEvent.rFAIL;
  88 			          }
  89 
  90 //System.out.println("slave response : " + response + "\n");
  91 
  92 				    // Pull out the return note
  93 				    left  = response.indexOf(noteFrame);
  94 				    left  = left + 5;
  95 				    right = response.lastIndexOf(noteFrame);
  96 				    right = right - 1;
  97 				    responseEvent.item = response.substring(left, right);
  98 				    	    			    
  99 				 } catch (Exception e) {
 100 				    // something bad happened.
 101 				    responseEvent.value = MEvent.rIO_ERROR;
 102 				    responseEvent.item  = new String("IO_ERROR");
 103 // System.out.println("Exception !!!!  rIOERROR\n" + e.getMessage() + "\n" + e.toString() + "\n");
 104 				 }
 105 				 break;
 106  			
 107 			   case MCommand.cmdSET_SLAVE_TARGET:
 108 			      try {
 109 				   targetURLText = new String("http://" + 
 110 							     (String)currentCommand.item +
 111 							     ":8050/");
 112 				} catch (Exception e) {
 113 				   // I dont care
 114 				}
 115 				break;
 116 
 117 			   case MCommand.cmdNULL:
 118 			   default:
 119 				responseEvent.value = MEvent.rNULL;
 120 				break;
 121 
 122 			}
 123 			eventQueue.put(responseEvent);
 124 			// okies.  gotta sleep for a sec and let target relax.
 125 			try {
 126 				this.sleep(400);
 127 			} catch (InterruptedException e) {
 128 				// Like I give a rats-ass about this lame exception...
 129 			}
 130 
 131 		} else {
 132 			idle = true;
 133 			try {
 134 				this.sleep(900);
 135 			} catch (InterruptedException e) {
 136 				// Like I give a rats-ass about this lame exception...
 137 			}
 138 
 139 		} // end if
 140 		
 141 	} // end while	
 142 
 143    } // end run()
 144 
 145 }     
 146